package com.winterwar.dao.hibernate;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.winterwar.base.Slot;
import com.winterwar.dao.SlotDAO;

public class SlotDAOHibernate extends HibernateDaoSupport implements SlotDAO {

	private Log log = LogFactory.getLog(SlotDAO.class);
	
	public Slot get(Integer slotID) {
		return (Slot) getHibernateTemplate().get(Slot.class, slotID);
	}

	public List getAll() {
		return (List) getHibernateTemplate().find("from Slot order by slotName");
	}

	public void remove(Integer slotID) {
		Object slot = getHibernateTemplate().load(Slot.class, slotID);
		getHibernateTemplate().delete(slot);
		getHibernateTemplate().flush();
	}

	public void save(Slot slot) {
		getHibernateTemplate().saveOrUpdate(slot);
		getHibernateTemplate().flush();
		if (log.isDebugEnabled()) {
			log.debug("userId set to: " + slot.getSlotID());
		}	
	}

	public List getByConID(Integer conID) {
		return getHibernateTemplate().find("from Slot where conID = " + conID.intValue() + " order by slotName");
	}
}
